<%= form_tag({}) do %>  
<%= hidden_field_tag 'back_url', url_for(params) %>  
<%= hidden_field_tag 'project_id', @project.id if @project %> 
<div class="autoscroll">
    <table class="contacts index">
    <tbody>
    <% previous_group = false %>    
    <% @contacts.each do |contact| %>  
        <% if @query.grouped? && (group = @query.group_by_column.value(contact)) != previous_group %>
          <% reset_cycle %>
          <tr class="group open">
            <td colspan="<%= @query.columns.size + 2 %>">
              <span class="expander" onclick="toggleRowGroup(this);">&nbsp;</span>
              <%= group.blank? ? 'None' : column_content(@query.group_by_column, contact) %> <span class="count">(<%= @contact_count_by_group[group] %>)</span>
              <%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}", "toggleAllRowGroups(this)", :class => 'toggle-all') %>
            </td>
          </tr>
          <% previous_group = group %>
        <% end %>

        <tr class="hascontextmenu">
            <td class="checkbox">
                <%= check_box_tag "selected_contacts[]", contact.id, false, :onclick => "toggleContact(event, this);" %>
            </td>
            <td class="avatar">
                    <%= link_to avatar_to(contact, :size => "32"), {:controller => 'contacts', :action => 'show', :project_id => @project, :id => contact.id}, :id => "avatar" %>
            </td>
            <td class="name">
                <h1><%= link_to contact.name, contact_url(contact) %></h1>
                <h2>
                    <%= link_to h(contact.website), contact.website_address, :only_path => true unless !contact.is_company %>
                    <%= mail_to contact.emails.first unless contact.is_company%>
                    <div><%= contact.phones.first %></div>
                </h2>
            </td>
            <td class="info">
                <div class="title_and_company" >
                    <%= h contact.job_title %>
                    <% if !contact.is_company %>
                        <%= " #{l(:label_at_company)} " unless (contact.job_title.blank? or contact.company.blank?) %> 
                        <%= h contact.company %> 
                    <% end %>
                </div>
                <div class="tags">
                    <%= render :partial => "tags_item", :collection => contact.tags, :locals => {:is_note => false}  %>
                </div>
            </td>
        </tr>         
    <% end %>
    </tbody>
    </table> 
 </div> 
 <% end %>


<p class="pagination"><%= pagination_links_full @contacts_pages, @contacts_count %></p>

